package top.hooray.delayedpayment.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import top.hooray.delayedpayment.entity.OrderStatus;
import top.hooray.delayedpayment.service.OrderService;

/**
 * @author hooray
 * @date 2021/3/9 23:25
 */
@Controller
public class PayController {

    private final OrderService orderService;

    public PayController(OrderService orderService) {
        this.orderService = orderService;
    }

    @RequestMapping("/pay/{orderId}")
    public String pay(@PathVariable Long orderId, Model model) {
        // 更新订单状态
        orderService.updateOrderStatus(orderId, OrderStatus.PAID);
        model.addAttribute("orderId", orderId);
        return "success";
    }
}
